package com.jy.project.controller;

import com.jy.project.dto.*;
import com.jy.project.service.DictService;
import com.jy.project.service.MaterialAttrFieldService;
import com.jy.project.util.ServiceResultUtils;
import com.jy.project.vo.DictVO;
import com.jy.project.vo.MaterialAttrFieldVO;
import com.jy.project.vo.QualityVO;
import com.jy.project.vo.TreeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/v1")
@CrossOrigin
public class DictController {

    @Autowired
    private DictService dictService;


    @Autowired
    private MaterialAttrFieldService materialAttrFieldService;
    /**
     * 展示公司
     * */
    @RequestMapping("/dict/listCompanyDictVO")
    @ResponseBody
    public Object listCompanyDictVO(){
        DictQueryDTO deptDTO=new DictQueryDTO();
        List<DictVO> list=dictService.listDeptDictVO(deptDTO);
        return ServiceResultUtils.success(list);
    }

    /**
     * 展示部门信息
     * */
    @RequestMapping("/dict/listDeptDictVO")
    @ResponseBody
    public Object listDeptDictVO(DictQueryDTO deptDTO){
        List<DictVO> list = dictService.listDeptDictVO(deptDTO);
        return ServiceResultUtils.success(list);
    }
    /**
     * 展示区域信息
     * */
    @RequestMapping("/dict/listRegionDictVO")
    @ResponseBody
    public Object listRegionDictVO(DictQueryDTO deptDTO){
        List<TreeVO> list=dictService.listRegionDictTreeVO(deptDTO);
        return ServiceResultUtils.success(list);
    }

    /**
     * 展示物资分类信息
     * */
    @RequestMapping("/dict/listAssetClassDictVO")
    @ResponseBody
    public Object listAssetClassDictVO(DictQueryDTO deptDTO){
        List<TreeVO> list=dictService.listAssetClassDictTreeVO(deptDTO);
        return ServiceResultUtils.success(list);
    }

    /**
     * 展示单位信息
     * */
    @RequestMapping("/dict/listUnitDictVO")
    @ResponseBody
    public Object listUnitDictVO(DictQueryDTO deptDTO){
        List<TreeVO> list=dictService.listUnitDictTreeVO(deptDTO);
        return ServiceResultUtils.success(list);
    }


    /**
     * 新增部门信息
     * */
    @RequestMapping("/dict/insertDept")
    @ResponseBody
    public Object insertDept(DeptDTO dto){
        dictService.insertDept(dto);
        return ServiceResultUtils.success(null);
    }


    /**
     * 新增区域信息
     * */
    @RequestMapping("/dict/insertRegion")
    @ResponseBody
    public Object insertRegion(RegionDTO dto){
        dictService.insertRegion(dto);
        return ServiceResultUtils.success(null);
    }

    /**
     * 新增物资类别信息
     * */
    @RequestMapping("/dict/insertAssetClassDTO")
    @ResponseBody
    public Object insertAssetClassDTO(AssetClassDTO dto){
        dictService.insertAssetClassDTO(dto);
        return ServiceResultUtils.success(null);
    }


    /**
     * 新增单位信息
     * */
    @RequestMapping("/dict/insertUnit")
    @ResponseBody
    public Object insertUnit(UnitDTO dto){
        dictService.insertUnit(dto);
        return ServiceResultUtils.success(null);
    }

    /**
     * 删除信息
     * */
    @RequestMapping("/dict/delete")
    @ResponseBody
    public Object delete(String dictNo){
        dictService.deleteDictByNo(dictNo);
        return ServiceResultUtils.success(null);
    }
    /**
     * 修改信息
     * */
    @RequestMapping("/dict/update")
    @ResponseBody
    public Object update(DictUpdateDTO dto){
        dictService.update(dto);
        return ServiceResultUtils.success(null);
    }

    /**
     * 插入质量状态
     * */
    @RequestMapping("/dict/insertQuality")
    @ResponseBody
    public Object insertQuality(QualityDTO qualityDTO){
        dictService.insertQuality(qualityDTO);
        return ServiceResultUtils.success(null);
    }

    /**
     * 展示质量列表
     * */
    @RequestMapping("/dict/listQualityVO")
    @ResponseBody
    public Object listQualityVO(DictQueryDTO dictQueryDTO){
        List<QualityVO> list = dictService.listQualityVO(dictQueryDTO);
        return ServiceResultUtils.success(list);
    }

    /**
     * 修改质量列表
     * */
    @RequestMapping("/dict/updateQuality")
    @ResponseBody
    public Object updateQuality(QualityDTO qualityDTO){
        dictService.updateQualityDTO(qualityDTO);
        return ServiceResultUtils.success(null);
    }

    /**
     * 资产类型获取资产拓展属性
     *
     * @param dictNo
     * @return
     */
    @GetMapping("/dict/{dictNo}/materialAttrFields")
    @ResponseBody
    public Object listMaterialAttrField(@PathVariable String dictNo) {
        List<MaterialAttrFieldVO> resultList = materialAttrFieldService.listMaterialAttrField(dictNo);
        return ServiceResultUtils.success(resultList);
    }
}
